<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/classes/DBHelper.class.jsp" %>
<%@ include file="/classes/CommonHelper.class.jsp" %>
<%@ include file="/classes/author.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>民意征集-后台列表</title>
<style type="text/css">
*{padding:0; margin:0 auto;} /* IE8*/
*+html *{padding:0; margin:0;}
* {margin:0; padding:0;}
body{margin:0px; font-size:12px; font-family:"宋体"; color:#000;background:url(../indeximages/ggcy_top_bg.jpg) no-repeat center top ;}

div{font-size:12px; text-align:left;}
 
a{color:#000; text-decoration:none;}
a:hover{ text-decoration:none; color:#F00;}
a:link {color:#000;} 
a:visited {color:#000;}
a:active {color:#000;}
ul,li{padding:0px; margin:0px; list-style-type:none;}

img{border:none;}

div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,blockquote{padding:0px; margin:0px;}
table,td,tr,th{font-size:12px;}
ul,li{margin:0px; padding:0px; list-style-type:none;}

.clear{clear:both;}
.transparent{background:transparent;}


.list_table{border:0px solid #ccc; border-collapse:collapse;}
.list_table th{font-weight:lighter;}
.list_table td{border:0px solid #ccc; height:32px; line-height:32px; text-align:center;}
.page{height:20px; line-height:20px; text-align:center; border:0px solid #ccc; border-top:none; margin:auto; padding:15px;}

.texthidden{
		width:100%;
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
	  }
	  
.texthidden a{color:#000; font-size:12px;}


</style>
</head>
<body>
<%

	String loginId=(String)(session.getAttribute("loginId")==null?"":session.getAttribute("loginId"));
	if(nullOrEmpty(loginId)){
		out.print("<script>alert(\"请登陆后操作！\");</script>");
		out.print("<script>window.location.href = 'http://htgl.cnsn.gov.cn/cas/login';</script>");
		return;
	}
	String userid=(String)session.getAttribute("userId");
	String title = getParameter(request,"title");
	String status = getParameter(request,"status");
	int currentPage = 1; 
	if(!nullOrEmpty(getParameter(request,"currentPage"))){
		currentPage = Integer.parseInt(getParameter(request,"currentPage"));
	}

	//判断是否是管理员
	String sqlRole = "select * from cms_user_role t1,cms_user t2 where t1.user_id = t2.user_id and t2.login_id = ? and t1.role_id = 'ADMINISTRATOR_ROLE'";
	Map<String,Object> m = getObject(sqlRole,new Object[]{loginId}); 
	if(null!=m){
		String sql = "select t1.*,t2.name dept_name from app_myzj_info t1,cms_department t2 where t1.dept_code = t2.code_name";
		List<Object> params = new ArrayList<Object>(); 
		if(!nullOrEmpty(title)){
			sql += " and title like ? ";
			params.add(title);
		}
		
		sql += " order by create_time desc";
		
		List<Map<String,Object>> list = queryForListPage(sql,params,currentPage,12);
		pageContext.setAttribute("list",list);
		int total = queryForPageCount(sql,params);
		
		Map<String,Integer> pageMap = new HashMap<String,Integer>();
		pageMap.put("currentPage",currentPage);
		pageMap.put("total",total);
		pageContext.setAttribute("page",pageMap);
	}else{
		//获取部门ID
		String dept_code = "";
		String sqlDept = "select t2.code_name from cms_user t1,cms_department t2 where t1.dept_id = t2.dept_id and login_id = ?";
		Map<String,Object> user = getObject(sqlDept,new Object[]{loginId});
		if(null!=user)
			dept_code = (String)user.get("code_name");
		
		//String sql = "select t1.*,t2.name dept_name from app_myzj_info t1,cms_department t2 where t1.dept_code = t2.code_name and t2.code_name = ?";
		//去掉部门，关联站点
		String sql = "select t1.*,t2.name dept_name from app_myzj_info t1,cms_department t2 where t1.dept_code = t2.code_name ";
		List<Object> params = new ArrayList<Object>(); 
		//params.add(dept_code);
		if(!nullOrEmpty(title)){
			sql += " and title like ? ";
			params.add(title);
		}
		
		/****************获取用户站点权限*******************///
		final String URL2 = "http://htgl.cnsn.gov.cn/website-webapp/services/WebsiteService";
		UserWebsite1 cd = new UserWebsite1();
		List<String []> sitecode = cd.getUserWebsite(userid,"3",URL2);
		if(sitecode.size()<6){
		String wheres = "";
			for (int i =0;i<sitecode.size();i++)
			{
				String []site = sitecode.get(i);
				wheres += "'"+site[1]+"',";
				//out.print(site[1]);
			}
			wheres = wheres.replace("'szfml'","''");
			wheres = wheres.substring(0,wheres.length()-1);
			sql += " and website_code in ("+wheres+")";
		}
		//out.print("sql"+sql);
		//out.print("sitecode"+sitecode.get(1)[1]);
		
		/****************获取用户站点权限*******************///
		
		sql += " order by create_time desc";
		
		List<Map<String,Object>> list = queryForListPage(sql,params,currentPage,15);
		pageContext.setAttribute("list",list);
		
		int total = queryForPageCount(sql,params);
		
		Map<String,Integer> pageMap = new HashMap<String,Integer>();
		pageMap.put("currentPage",currentPage);
		pageMap.put("total",total);
		pageContext.setAttribute("page",pageMap);
		pageContext.setAttribute("sitecode",sitecode);
	}
	%>


	  <div style=" width:100%;height:508px;_height:508px; position:relative;  " >

	<div style=" height:43px;">
    	<div style=" font-size:1px; height:10px;"></div>
		<a href="myzj_save.jsp?r=<%=new Date().getTime() %>" ><img src="images/xz.jpg"  /></a>
    </div>
	<form name="myform" action="myzj_list.jsp?r=<%=new Date().getTime() %>">
		
        <div style=" height:455px;"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="list_table">
			<tr  bgcolor="#CCCCCC" style="font-weight: bold;">
				<td width="50%" height="33" style="border-bottom:1px solid #ccc; font-size:14px;">征集标题</td>
				<td width="21%" style="border-bottom:1px solid #ccc; font-size:14px;">发布时间</td>
				<td width="16%" style="border-bottom:1px solid #ccc; font-size:14px;">状态</td>
				<td width="13%" style="border-bottom:1px solid #ccc; font-size:14px;">操作</td>
			</tr>
			<c:forEach items="${list }" var="info">
			<tr>
				<td height="32" style="border-bottom:1px dashed #ccc;text-align:left; text-indent:10px;font-size:12px;">
                	<div class="texthidden">
                		<a href="myzj_modify.jsp?guid=${info.guid }&r=<%=new Date().getTime() %>" >.${info.title }</a> 
                    </div>
                </td>
				<td style="border-bottom:1px dashed #ccc;font-size:12px;">
					<c:if test="${null!=info.create_time }">
					<f:formatDate value="${info.create_time }" pattern="yyyy-MM-dd"/>
					</c:if>				</td>
				<td style="border-bottom:1px dashed #ccc;font-size:12px;">${info.status==1 ? "已发布":"草稿" }</td>
				<td style="border-bottom:1px dashed #ccc;">
					<a href="myzj_modify.jsp?guid=${info.guid }&r=<%=new Date().getTime() %>" >修改</a>
					<a href="myzj_verify.jsp?guid=${info.guid }&r=<%=new Date().getTime() %>" >审核网友回复</a>
				</td>
			</tr>
			</c:forEach>
			<!--<tr>
				<td colspan="4">
				<jsp:include page="/common/page.jsp" >
		    		<jsp:param value="${page.currentPage }" name="currentPage"/>
					<jsp:param value="${page.total }" name="totalRecord"/>
					<jsp:param value="15" name="pageSize"/>
					<jsp:param value="myform" name="formName"/>
					<jsp:param value="<%=new Date().getTime() %>" name="r"/>
		    	</jsp:include>
		    	</td>
		    </tr>-->
		</table></div>
        <div style=" text-align:center;">
        	<jsp:include page="/common/page.jsp" >
		    		<jsp:param value="${page.currentPage }" name="currentPage"/>
					<jsp:param value="${page.total }" name="totalRecord"/>
					<jsp:param value="12" name="pageSize"/>
					<jsp:param value="myform" name="formName"/>
					<jsp:param value="<%=new Date().getTime() %>" name="r"/>
		    	</jsp:include>
        </div>
	</form>
    
    </div>
</body>
</html>